<template>
  <div class="card-out-container">
    <a-form layout="inline">
      <a-form-item :label="$t('basicData.workType')">
        <a-input v-model:value.trim="queryParam.name" :placeholder="$t('basicData.pleaseInputWorkName')" @keyup.enter="loadData" allowClear />
      </a-form-item>
      <a-form-item>
        <a-space>
          <a-button type="primary" @click="loadData">{{ $t('common.see') }}</a-button>
          <a-button @click="searchReset">{{ $t('common.reset') }}</a-button>
        </a-space>
      </a-form-item>
    </a-form>
    <div class="list-operate">
      <a-button type="primary" @click="handleAdd">{{ $t('common.add') }}</a-button>
      <a-button type="warning" :disabled="!selectedRowKeys.length" @click="handleDelete(null)">{{ $t('common.delMore') }}</a-button>
    </div>
    <a-table rowKey="id" :loading="loading" bordered size="small" :dataSource="dataSource" :columns="columns" :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange, fixed: 'left'}" :pagination="ipagination" :scroll="{y: 'calc(100vh - 390px)'}">
      <template #bodyCell="{ column, record }">
        <template v-if="column.key === 'code'">
          <span class="code-link" @click="handleDrawDetail(record)">{{record.code}} </span>
        </template>
        <template v-else-if="column.key === 'operate'">
          <span class="table-operate-container">
            <a-button type="link" class="primary-link" @click="handleEdit(record)">{{ $t('common.editor') }}</a-button>
            <a-divider type="vertical" />
            <a-button type="link" class="warning-link" @click="handleDelete(record.id)">{{ $t('common.del') }}</a-button>
          </span>
        </template>
      </template>
    </a-table>

    <commone-modal ref="modalForm" tableName="workPro" :cloSapn="24" modalTitle="{{$t('basicData.workType')}}" @ok="modalFormOk">
    </commone-modal>
    <detail-draw ref="detailForm"></detail-draw>
  </div>
</template>

<script>
import { ListMixinPm } from '@/mixin/listMixinPm.js'
import CommoneModal from '@/components/commonModal/normalModal.vue'
import DetailDraw from './modules/detailDraw.vue'
import { formatTime } from '@/utils'
export default {
  name: 'workPro',
  mixins: [ListMixinPm],
  components: {
    CommoneModal,
    DetailDraw
  },
  data () {
    return {
      url: {
        list: '/api/basic/profession/list',
        delete: '/api/basic/profession/delete'
      },
      columns: [
        {
          title: this.$t('common.sequenceNo'), dataIndex: 'index', key: 'index', align: 'center',
          customRender: ({ index }) => {
            return index + 1
          }
        },
        { title: this.$t('basicData.workCodes'), dataIndex: 'code', key: 'code', align: 'center' },
        { title: this.$t('basicData.workName'), dataIndex: 'name', key: 'name', align: 'center' },
        { title: this.$t('common.remark'), dataIndex: 'remark', key: 'remark', align: 'center' },
        {
          title: this.$t('common.createTime'), dataIndex: 'createTime', key: 'createTime', align: 'center', width: 170,
          customRender: ({ text }) => {
            return formatTime(text, 'YYYY-MM-DD HH:mm:ss')
          }
        },
        {
          title: this.$t('common.updateTime'), dataIndex: 'updateTime', key: 'updateTime', align: 'center', width: 170,
          customRender: ({ text }) => {
            return formatTime(text, 'YYYY-MM-DD HH:mm:ss')
          }
        },
        { title: this.$t('common.operate'), dataIndex: 'operate', key: 'operate', align: 'center', width: 130 },
      ]
    }
  }
}
</script>